package com.lorenzogao.pley.common

import android.app.Application
import android.os.Environment
import android.os.Environment.DIRECTORY_DOWNLOADS
import com.lorenzogao.pley.common.util.ACache
import dagger.Module
import dagger.Provides
import retrofit2.Retrofit
import zlc.season.rxdownload2.RxDownload
import java.io.File
import javax.inject.Singleton

/**
 * 作者：Lorenzo Gao
 * Date: 2018/1/12
 * Time: 13:43
 * 邮箱：2508719070@qq.com
 * Description:
 */
@Module
class DownloadModule {

    @Provides
    @Singleton
    fun providesRxDownload(appAppclcation: Application, retrofit: Retrofit, downDir: File): RxDownload {

        ACache.get(appAppclcation).put(Constant.APK_DOWNLOAD_DIE,downDir.path)

        return RxDownload.getInstance(appAppclcation)
                .defaultSavePath(downDir.path)
                .retrofit(retrofit)
                .maxDownloadNumber(10)
                .maxThread(10)


    }

    @Singleton
    @Provides
    fun provideDownloadDir(): File {

        return Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)
    }


}